﻿using SharpSoft.Lexing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpSoft.Documentation.Html.CSS
{
    /// <summary>
    /// 标记
    /// </summary>
    internal struct SelectorToken : IToken
    {
        public SelectorToken(int pos, int lng, SelectorTokenType type, string content = null)
        {
            this._Type = type;
            this._Content = content;
            this._Position = pos;
            this._Length = lng;
        }
        private string _Content;
        /// <summary>
        /// 标记的内容
        /// </summary>
        public string Content
        {
            get { return _Content; }
        }

        private SelectorTokenType _Type;
        /// <summary>
        /// 标记类型
        /// </summary>
        public SelectorTokenType Type
        {
            get { return _Type; }
        }

        private int _Position;
        /// <summary>
        /// 标记在源中的位置
        /// </summary>
        public int Position
        {
            get { return _Position; }
        }

        private int _Length;
        /// <summary>
        /// 标记内容在源中所占的长度（字符个数）
        /// </summary>
        public int Length
        {
            get { return _Length; }
        }


        private static SelectorToken _EndToken = new SelectorToken(int.MaxValue, 1, SelectorTokenType.End);

        public static SelectorToken EndToken
        {
            get
            {
                return _EndToken;
            }
        }

        public override string ToString()
        {
            return string.Format("位置：{0},长度：{1},标记类型：{2},内容:{3}",Position,Length,Type,Content);
        }

    }
    /// <summary>
    /// 标记类型
    /// </summary>
    internal enum SelectorTokenType
    {
        /// <summary>
        /// @，框架选择器，附加
        /// </summary>
        Frame,
        /// <summary>
        /// .,类名选择器
        /// </summary>
        Class,
        /// <summary>
        /// #,Id选择器
        /// </summary>
        Id,
        /// <summary>
        /// [,标识属性选择器规则的开始
        /// </summary>
        OpenBracket,
        /// <summary>
        /// ],标识属性选择器规则的结束
        /// </summary>
        CloseBracket,
        /// <summary>
        /// :,伪类标识
        /// </summary>
        PseudoClass,
        /// <summary>
        /// (……),伪类参数
        /// </summary>
        PseudoClassParameter,
        /// <summary>
        /// , ,多个选择器的分隔符
        /// </summary>
        Comma,
        /// <summary>
        /// =,属性相等匹配
        /// </summary>
        MatchTypeEqual,
        /// <summary>
        /// ~=,属性项包含匹配
        /// </summary>
        MatchTypeItem,
        /// <summary>
        /// ^=,属性子串开始匹配
        /// </summary>
        MatchTypeStartWith,
        /// <summary>
        /// $=,属性子串结束匹配
        /// </summary>
        MatchTypeEndWith,
        /// <summary>
        /// *=,属性子串包含匹配
        /// </summary>
        MatchTypeContains,
        /// <summary>
        /// |=,属性限定匹配（匹配完全等于属性值或以“属性值-”开始）
        /// </summary>
        MatchTypeSpecific,
        /// <summary>
        ///  ,后代
        /// </summary>
        Progeny,
        /// <summary>
        /// >,直接后代
        /// </summary>
        Child,
        /// <summary>
        /// +,同级的下一个
        /// </summary>
        NextOne,
        /// <summary>
        /// ~,同级之后
        /// </summary>
        NextN,
        /// <summary>
        /// 常规量
        /// </summary>
        Literal,
        /// <summary>
        /// 字符串
        /// </summary>
        String,
        /// <summary>
        /// 选择器结束标记，遇到Source的结束标记("\0")或Css样式正文标记("{")
        /// </summary>
        End,
    }
}
